package day5;


public class RentCompany {
    private String name;
    private String adress;
    private String number;
    private Vehicle[] vehicles = new Vehicle[20];//机动车数组
    private Rent[] rent = new Rent[100];//租赁记录数组
    private int count = 8;//车数量
    private int sum = 0;//租车记录


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }


    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }


    public RentCompany(String name, String adress, String number) {
        this.name = name;
        this.adress = adress;
        this.number = number;

    }

    public void show() {
        System.out.println("欢迎光临" + name + "租车公司，本公司地址在" + adress + "电话号码是" + number);
    }


    public RentCompany() {
        vehicles[0] = new Car("皖A88888", "大众", 800, 5, "当前可租", "途岳");
        vehicles[1] = new Car("皖A55555", "奇瑞", 200, 5, "当前可租", "瑞虎");
        vehicles[2] = new Car("皖A67465", "别克", 500, 5, "当前可租", "GL8");
        vehicles[3] = new Car("皖A66666", "保时捷", 900, 5, "当前可租", "911");
        vehicles[4] = new Bus("皖A65233", "金杯", 800, 16, "当前可租");
        vehicles[5] = new Bus("皖A65423", "金杯", 800, 16, "当前可租");
        vehicles[6] = new Bus("皖A52454", "金龙", 1500, 34, "当前可租");
        vehicles[7] = new Bus("皖A20221", "金龙", 1500, 34, "当前可租");
    }


    //查看车辆信息
    public void check() {
        System.out.println("<<<<车辆信息>>>>>");
        for (int i = 0; i < count; i++) {
            if (vehicles[i] != null) {
                vehicles[i].show();
            } else {
                break;
            }
        }
    }

    public void show(String chioce) {
        for (int i = 0; i < count; i++) {
            if (!vehicles[i].getState().equals("当前可租")) {
                return;
            }
        }
        for (int i = 0; i < count; i++) {
            if (chioce.equals("轿车") && vehicles[i] instanceof Car) {

                System.out.println(vehicles[i].getVehicleid() + " " + vehicles[i].getBrand() + " " + vehicles[i].getRent() + " " + vehicles[i].getState());

            } else if (chioce.equals("客车") && vehicles[i] instanceof Bus) {

                System.out.println(vehicles[i].getVehicleid() + " " + vehicles[i].getBrand() + " " + vehicles[i].getRent() + " " + vehicles[i].getState());

            }
        }
    }

    //租车

    public void rentcar(String name, String chepai, int days) {
        for (int i = 0; i < count; i++) {
            if (vehicles[i].getState().equals("当前可租")) {
                if (vehicles[i].getVehicleid().equals(chepai)) {
                    System.out.println("租赁成功");
                    System.out.println("租车的价格为" + vehicles[i].calcRent(days));
                    vehicles[i].setState("已租出");
                    rent[sum] = new Rent(name, chepai, vehicles[i].getBrand(), days, vehicles[i].calcRent(days));
                    sum++;
                }
            }
        }
    }

    //还车
    public void ruturncar(String carnumber) {
        for (int i = 0; i < count; i++) {
            if (vehicles[i].getState().equals("已租出") && vehicles[i].getVehicleid().equals(carnumber)) {
                vehicles[i].setState("当前可租");
                System.out.println("已还车");
                return;
            }
        }
        System.out.println("还车失败");

    }

    //报废车辆
    public boolean scrap(String carnumber) {
        for (int i = 0; i <count ; i++) {
            if (vehicles[i].getState().equals("已租出")){
                System.out.println("您选择的车辆出租中，无法报废");
                return false;
            }
        }
        for (int i = 0; i < count; i++) {
            if (vehicles[i].getVehicleid().equals(carnumber)) {
                vehicles[i] = null;
                for (int j = i; j < count - 1; j++) {
                    vehicles[j] = vehicles[j + 1];
                }
                vehicles[count - 1] = null;
                count--;
                System.out.println("您选择的车辆已报废");
                return true;
            }
        }
        return false;
    }

    //加新车
    public void buy(Vehicle c) {
        if (count >= vehicles.length) {
            Vehicle[] a = new Vehicle[vehicles.length + 100];
            for (int i = 0; i < count; i++) {
                a[i] = vehicles[i];
            }
            vehicles = a;
        }
        vehicles[count++] = c;
//            vehicles[count++].setState("当前可租");//错误，在测试类里面直接定义


    }

    //增加出租记录
    //显示租赁人信息
//    public void addsum(String chepai,String name,String brand,int days,int money) {
//      if (sum>rent.length){
//          Rent[]a=new Rent[rent.length+100];
//          for (int i = 0; i <sum; i++) {
//              a[i]=rent[i];
//          }
//          rent=a;
//      }
//      rent[sum++]=new Rent(name,chepai,brand,days,money);
//}
    public void showsum() {
       if  (sum > rent.length) {
                Rent[] a = new Rent[rent.length + 100];
                for (int i = 0; i < sum; i++) {
                    a[i] = rent[i];
                }
            rent = a;
            for (int i = 0; i < sum; i++) {
                System.out.println(rent[i]);
            }
        }
    }

    public void sumMoney() {

    }
}
